package com.pipe.servicepipe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pipe.commonutils.consts.PipeComConst;
import com.pipe.servicepipe.entity.PipeCustomer;
import com.pipe.servicepipe.entity.vo.PipeCustomerQuery;
import com.pipe.servicepipe.mapper.PipeCustomerMapper;
import com.pipe.servicepipe.service.PipeCustomerService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 客户表 服务实现类
 * </p>
 *
 * @author hetao
 * @since 2020-07-12
 */
@Service
public class PipeCustomerServiceImpl extends ServiceImpl<PipeCustomerMapper, PipeCustomer> implements PipeCustomerService {

    @Override
    public void findCustomerByPage(Page<PipeCustomer> pageParam, PipeCustomerQuery customerQuery) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.orderByAsc("create_time", "modified_time");
        if (customerQuery != null) {
            Integer phone = customerQuery.getPhone();
            String name = customerQuery.getName();
            String start = customerQuery.getStartTime();
            String end = customerQuery.getEndTime();
            int type = customerQuery.getType() == null ? PipeComConst.ClientType.ALL : customerQuery.getType();
            if (phone != null) {
                queryWrapper.likeRight("phone", phone);
            }
            if (StringUtils.isNotEmpty(name)) {
                queryWrapper.like("name", name);
            }
            if (StringUtils.isNotEmpty(start)) {
                queryWrapper.ge("create_time", start);
            }
            if (StringUtils.isNotEmpty(end)) {
                queryWrapper.le("create_time", end);
            }
            if (PipeComConst.ClientType.ALL != type) {
                queryWrapper.ge("c_type", type);
            }
        }
        this.baseMapper.selectPage(pageParam,queryWrapper);
    }
}
